import logging

# 创建一个logger
logger = logging.getLogger("tortoise")
logger.setLevel(logging.DEBUG)

# 创建一个handler，用于写入日志文件
handler = logging.FileHandler("tortoise.log")  # 或者其他文件路径
handler.setLevel(logging.DEBUG)

# 定义handler的输出格式
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)

# 给logger添加handler
logger.addHandler(handler)
TORTOISE_ORM = {
    'connections': {
        'default': {
            # 'engine': 'tortoise.backends.asyncpg',  # PostgreSQL
            'engine': 'tortoise.backends.mysql',
            'credentials': {
                'host': '127.0.0.1',
                'port': 3306,
                'user': 'root',
                'password': '123456',
                'database': 'fastapi',
                'charset': 'utf8mb4',
                'autocommit': True,
                'echo': True,
                'minsize': 1,
                'maxsize': 10,
            }
        }
    },
    'apps': {
        'models': {
            'models': ['models', 'aerich.models'],
            'default_connection': 'default'
        }
    },
    'use_tz': False,
    'timezone': 'Asia/Shanghai',
    'debug': True,
    'log_queries': True,
    'log_queries_ms': 100,
    'log_queries_ms_level': 'INFO',
    'logging_config': {
           "version": 1,
           "formatters": {
               "default": {"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s"}
           },
           "handlers": {
               "console": {
                   "class": "logging.StreamHandler",
                   "formatter": "default",
                   "level": "DEBUG",
               },
           },
           "root": {"level": "DEBUG", "handlers": ["console"]},
       },
}
